package com.example.myapplication.services;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.support.annotation.Nullable;

import com.example.myapplication.nettyheart.TimeClient;
import com.example.myapplication.nettyheart.TimeClientHandler;

public class NettyStatusService extends Service {

    private Thread mThread;
    private boolean issend = true;
    private boolean isConnect = false;
    private Context mContext;

    @Override
    public void onCreate() {
        super.onCreate();
        mContext = this;
        mThread = new Thread(new Runnable() {
            @Override
            public void run() {
                HttpMsg();
//                while(true){
//                    try {
//                        if(issend){
//                            LogUtils.i("dove", "心跳链接执行。。。。。。");
//                            issend = false;
//                        }
//                        Thread.sleep(TimeUtils.getHeartTime()*1000);
//                    }catch(Exception e){
//                        e.printStackTrace();
//                    }
//                }
            }
        });
        mThread.start();
    }

    /**
     * 心跳请求
     */
    private void HttpMsg() {
        if(!isConnect){
            try {
                TimeClientHandler timeClientHandler = new TimeClientHandler("hello world");
                TimeClient.init().connect(8888,"172.20.35.56",timeClientHandler);
                isConnect = true;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }else{

        }
    }

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }
}
